#include "stdafx.h"
#include "Enum.h"
#include "config/Def.h"

using namespace unigame;

std::vector<std::vector<Enum*>*>* Enum::s_list = 0;

Enum::Enum(int32u listIndex)
{	
	if(s_list == 0)
	{
		s_list = uni_new std::vector<std::vector<Enum*>*>();
	}
	while(listIndex >= (int32u)s_list->size())
	{
		s_list->push_back(0);
	}
	m_vector = (*s_list)[listIndex];
	if(m_vector == 0)
	{
		m_vector = uni_new std::vector<Enum*>();
		(*s_list)[listIndex] = m_vector;
	}

	m_index = m_vector->size();
	m_vector->push_back(this);
}

void Enum::destory()
{
	if(s_list != 0)
	{
		for(int i = 0, size = s_list->size(); i < size; ++i)
		{
			std::vector<Enum*>* v = (*s_list)[i];
			if(v != 0)
			{
				v->clear();
				delete v;
			}
		}
		s_list->clear();
		delete s_list;
		s_list = 0;
	}
}